#include <TFile.h>
#include <TTree.h>
#include <TH1D.h>
#include <iostream>
#include <TCanvas.h>
using namespace std;
void DrawHit2220(int widcoin)
{
    gStyle->SetOptStat(111111);
    TFile *file = new TFile("../RootData/Coin_Sort_DAS2_data1_20250714T222403_0.root", "read");
    TTree *treeCoin = new TTree();
    TCanvas *c1 = new TCanvas("c1", "c1", 8000, 6000);
    c1->Divide(1, 2);
    TH1D *hHit22 = new TH1D(Form("hHit22_%d", widcoin), "hHit22", 10, 0, 10);
    TH1D *hHit20 = new TH1D(Form("hHit20_%d", widcoin), "hHit20", 10, 0, 10);

    file->GetObject("treeCoin", treeCoin);
    short nHit[3][16];
    treeCoin->SetBranchAddress("nHit", nHit);
    for (int iEvent = 0; iEvent < treeCoin->GetEntries(); iEvent++)
    {
        treeCoin->GetEntry(iEvent);
        if (nHit[2][0] > 0 && nHit[2][2] > 0)
        {
            hHit22->Fill(nHit[2][2]);
            hHit20->Fill(nHit[2][0]);
        }
    }
    c1->cd(1);
    hHit22->Draw();
    c1->cd(2);
    hHit20->Draw();
    c1->SetTitle(Form("hit_2220%d", widcoin));
    c1->SaveAs(Form("../RootData/Hit_2220%d.png", widcoin));
}
int main(int argc, char const *argv[])
{
    int widcoin = 100;
    if (argc > 1)
    {
        widcoin = std::atoi(argv[1]);
    }

    DrawHit2220(widcoin);
    return 0;
}
